/**
 * @description shop router
 * @author 李哲
 */

const router = require('koa-router')()
const { successModel } = require('../res-model/index');
const { getShopList, getShop, getProductList } = require('../controller/shop');

router.prefix('/api/shop')

//获取商店列表
router.get('/hot-list', async (ctx, next) => {
    const shopList = await getShopList();
    ctx.body = new successModel(shopList);
})
//获取单个商店
router.get('/:id', async (ctx, next) => {
    const id = ctx.params.id;
    const newShop = await getShop(id);
    ctx.body = new successModel(newShop);
})
//获取商品列表
router.get('/:id/products', async (ctx, next) => {
    const tab = ctx.query.tab || 'all'
    console.log(tab);
    const id = ctx.params.id
    const newProduct = await getProductList(id, tab)
    ctx.body = new successModel(newProduct);
})
module.exports = router